<template>
  <div class="advice">
    <div class="cha" @click="goBack">×</div>

    <img src="@/assets/imgs/middleWork/advice.png" class="img" />
    <div class="form">
      <div class="btnWrap">
        <div class="btn" :class="key == 1 ? 'active' : ''" @click="key = 1">
          功能缺陷
        </div>
        <div class="btn" :class="key == 2 ? 'active' : ''" @click="key = 2">
          使用体验
        </div>
        <div class="btn" :class="key == 3 ? 'active' : ''" @click="key = 3">
          其他
        </div>
      </div>
      <div class="text">请填写您的体验建议</div>
      <el-input
        type="textarea"
        v-model="adviceDesc"
        :rows="6"
        placeholder="欢迎吐槽，我们将及时改正。谢谢～"
        maxlength="300"
        show-word-limit
      ></el-input>
      <div class="text">联系方式</div>
      <el-input
        v-model="relationCode"
        placeholder="如果您需要我们的反馈，可留下联系方式"
        maxlength="50"
        show-word-limit
      ></el-input>
      <el-button class="width160" @click="goBack">取消</el-button>
      <el-button class="width160" type="primary" @click="submit"
        >提交</el-button
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "middleWorkAdvice",
  data() {
    return {
      relationCode: "",
      adviceDesc: "",
      key: "1",
    };
  },
  methods: {
    goBack() {
      this.$router.back();
    },
    submit() {
      if (!this.adviceDesc) {
        return this.$message.warning("请填写您的体验建议！");
      }
      this.$http
        .post("/api/advice/save", {
          adviceType: this.key,
          relationCode: this.relationCode,
          adviceDesc: this.adviceDesc,
        })
        .then((res) => {
          if (res.code === "0000") {
            this.goBack();
            this.$message.warning("非常感谢您的建议，我们会尽快反馈！");
          }
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.advice {
  width: 596px;
  height: 700px;
  background: #ffffff;
  box-shadow: 2px 11px 22px 0px rgba(208, 227, 251, 0.41);
  border-radius: 30px;
  margin: auto;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  .cha {
    right: 30px;
    top: 10px;
    position: absolute;
    font-size: 24px;
    cursor: pointer;
  }
  .img {
    width: 596px;
  }
  .form {
    padding: 30px 40px;
    color: #666;
    .btnWrap {
      display: flex;
      // justify-content: space-between;
      .active {
        background: #03bfc6;
        color: #fff;
      }
    }

    .btn {
      width: 110px;
      height: 36px;
      background: #f0f0f0;
      border-radius: 4px;
      display: inline-block;
      text-align: center;
      line-height: 36px;
      cursor: pointer;
      margin-right: 20px;
      &:nth-child(4n + 4) {
        margin-right: 0;
      }
    }
    .text {
      margin-top: 30px;
      margin-bottom: 14px;
    }
    .width160 {
      width: 120px;
      margin-top: 50px;
      height: 36px;
      border-radius: 6px;
    }
  }
}
</style>
